<?php
namespace Admin\Controller;
use Think\Controller;
class SlidersController extends AuthController{

    public function index()
    {
        $this->page_title="چوڭ ئايلانما ئېلان";
        $this->adds=M('ad')->select();
        $this->display();
    }

    //添加
    public function add()
    {
        $this->page_title="چوڭ ئايلانما ئېلان قوشۇش";
        $this->display();
    }

    //封面图片
    public function uploadAd()
    {
        $config = array(
            'maxSize'    =>    3145728,
            'rootPath'   =>    './Uploads/',  //根目录
            'savePath'   =>    'ad/',    //根目录下的目录
            'saveName'   =>    array('uniqid',''),
            'exts'       =>    array('jpg', 'gif', 'png', 'jpeg'),
            'autoSub'    =>    true,
            'subName'    =>    array('date','Ymd'),
        );
        $upload = new \Think\Upload($config);// 实例化上传类
        //上传图片
        $info=$upload->upload();
        if(!$info) $this->error($upload->getError());
        $thumb=$info['Filedata'];
        $savepath=$thumb['savepath'];
        $savename=$thumb['savename'];
        $pathSave='Uploads/'.$savepath.$savename;  //图片的完美地址
//        //处理图片大小
//        $image = new \Think\Image();
//        //打开图像资源
//        $image->open($pathSave);
//        //裁剪图片
//        $image->thumb(1920,500,\Think\Image::IMAGE_THUMB_FILLED)->save($pathSave);
        $this->ajaxReturn($pathSave);

    }

    //提交
    public function addhend()
    {
       $rules=[
           ['adthumb','require','请选择图片'],
       ];
       if(!M('ad')->validate($rules)->create()) $this->error(M('ad')->getError());
       if(!M('ad')->add(I('post.'))) $this->error('添加失败！');
       $this->success('添加成功了',U('Sliders/index'),1);
    }


}